<?php

class Api{
    function post($req){
        $account  = $req->body->account;
        $password = $req->body->password;
        $row = pt\db\Mysql::init()->row("select id from user where email = ? and password = ?",$account,md5($password));
        if($row){
            $userId = $row['id'];
            $token = Auth::gen_token($userId,null);
        }else{
            throw new ErrHttp("用户名和密码不正确",5001);
        }
        $res = array(
            "userId"=>$userId,
            "expire"=>time(),
            "issued_at"=>time(),
            "token"=>$token['token']
        );
        return $res;
    }
}
